// import axios from  'axios'
// import store from '@/store'
// export  function  request(config){
//     const instance = axios.create({
//         baseURL:"https://qiaohuhu.xyz:8000/api",
//         timeout:5000
//     })
//     // 请求拦截
//     instance.interceptors.request.use(
//         config => {
//             // console.log(store.getters.getToken)
//             let t = window.localStorage.getItem(token)
//             console.log(window.localStorage.getItem(token))
//             if (t) {
//                 config.headers['Authorization'] = t
//             }
//             console.log(config)
//             return config
//         },
//         error => {
//             return Promise.reject(error)
//         }
//     );
//     // // 响应拦截
//     instance.interceptors.response.use(res => {
//         return res.data
//     },err => {
//         console.log(err);
//     })
//     return instance
// }
// // export 
// // baseURL: 'https://lianghj.top:3000'

import axios from 'axios'
import { Message } from 'element-ui'
import store from '@/store'
// import { getToken } from '@/utils/auth'
import qs from 'qs'
// console.log(store)
const service = axios.create({
  timeout: 60000
})

service.interceptors.request.use(
  config => {
    if (store.getters.getToken) {  
      config.headers['Authorization'] = store.getters.getToken
      // config.headers['Access-Control-Allow-Origin'] = '*'
      // console.log(config.headers['Authorization'])
    }
    // console.log(config);
    return config
  },
  error => {
    return Promise.reject(error)
  }
)

service.interceptors.response.use(
  response => {
    const res = response

    if (res.status !== 200) {
      Message({
        message: 'Error',
        type: 'error',
        duration: 5 * 1000
      })
      return Promise.reject(res)
    } else {
      // console.log(res)
      return res.data
    }
  },
  error => {
    return Promise.reject(error)
  }
)
export const upload = (url, params) => {
  return service.post(url, params, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export default service
